package ioperation;

import book.BOOK;
import book.BOOKLIST;

import java.util.Scanner;

public class DELOPERATION implements IOPERATION{
    public void work(BOOKLIST booklist){
        System.out.println("删除图书.....");
        int current = booklist.getUsedSize();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的书名：");
        String name = scanner.nextLine();
        int pos = -1;
        for(int i = 0; i < current; i ++){
            BOOK book = booklist.getBooks(i);
            if(book.getName().equals(name)){
                pos = i;
                break;
            }
        }
        if(pos == -1){
            System.out.println("没有这本书");
            return;
        }
        for(int i = pos; i < current - 1; i ++){
             BOOK book = booklist.getBooks(i + 1);
             booklist.setBooks(i,book);
        }
        System.out.println("删除成功");
    }
}
